-- msg_artifact_durability
-- Created by cheng Apr/1/2015
-- 下发神器耐久信息

-- 神器起始编号
local ARTIFACT_START_ID = 6001;

return function(lpc)
    -- 先清理下旧的数据

    trace("msg_artifact_durability", lpc.dura_info);

    local buffer = Buffer.create(lpc.dura_info);
    local offset = 1;
    local size = Buffer.size(buffer);
    local duraInfo = {};
    while (offset <= size) do
        local amount = Buffer.getu16(buffer, offset);
        if (amount > 0) then
            -- 服务器的下标从0开始，而lua的下标从1开始，因此这里需要-1
            local classId = ARTIFACT_START_ID + math.modf(offset / 2);  
            duraInfo[classId] = amount;
        end

        -- 继续下一个道具
        offset = offset + 2;
    end
    
    ME.user.dbase:set("artifact_durability", duraInfo);
end
